package com.software.exception;

import com.software.base.ResultInfo;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @BelongsProject: Second-hand-trading-platform
 * @BelongsPackage: com.software.exception
 * @Author: wyj
 * @CreateTime: 2024-02-27  14:02
 * @Description:
 * @Version: 1.0
 */
@ControllerAdvice
public class GlobalExceptionResolver {
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public ResultInfo exceptionHandler(Exception e) {

        if (e instanceof ParamsException) {
            ParamsException exception = (ParamsException) e;
            return ResultInfo.error(exception.getMsg());
        } else if (e instanceof NullPointerException) {
            ResultInfo.error("空值");
        }
        return ResultInfo.error("服务器异常了");

    }
}
